//
//  APVideoRecorderControlView.m
//  AqualPolo
//
//  Created by dong on 2024/5/16.
//

#import "APVideoRecorderControlView.h"

@implementation APVideoRecorderControlView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _recordControl = [[APVideoRecordControl alloc] init];
        [self addSubview:_recordControl];
        [_recordControl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(24);
            make.left.right.equalTo(self);
            make.bottom.equalTo(self);
        }];
     
        _progressControl = [[APVideoProgressControl alloc] init];
        _progressControl.hidden = true;
        [self addSubview:_progressControl];
        [_progressControl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(24);
            make.left.right.equalTo(self);
            make.bottom.equalTo(self);

        }];
        
    }
    return self;
}




@end


@implementation APVideoRecordControl

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _recorderButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_recorderButton setTitleColor:LYRGBColor(87, 61, 255) forState:UIControlStateNormal];
        _recorderButton.titleLabel.font = [LYFont fontWithSize:16 fontName:LYFontNamepfr];
        [_recorderButton setTitle:@"10s" forState:UIControlStateNormal];
        [_recorderButton setBackgroundImage:[UIImage imageNamed:@"record_btn_bg"] forState:UIControlStateNormal];
        [self addSubview:_recorderButton];
        [_recorderButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(82, 82));
        }];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [LYFont fontWithSize:24 fontName:LYFontNamepfr];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.text = @"Click to start recording";
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_recorderButton.mas_bottom).offset(14);
            make.left.right.equalTo(self);
        }];
    }
    return self;
}

@end


@implementation APVideoProgressControl


- (void)setProgress:(CGFloat)progress{
    _progress = progress;
    LYLog(@"---------%f",progress);
    self.progressView.progress = (10 - progress) * 0.1;
    self.progressView.contentText = [NSString stringWithFormat:@"%d",(int)progress];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _progressView = [[FLCircleProgressView alloc] init];
        _progressView.backgroundColor = LYRGBAColor(255, 255, 255,0.3);
        _progressView.layer.cornerRadius = 32;
        _progressView.layer.masksToBounds = true;
        _progressView.trackColor = LYRGBAColor(255, 255, 255,0.3);
        _progressView.lineWidth = 2;
        _progressView.progressColor = LYRGBColor(154, 255, 213);
        _progressView.contentTextFont = [LYFont fontWithSize:16 fontName:LYFontNamepfr];
        _progressView.contentTextColor =  LYRGBColor(154, 255, 213);
        _progressView.contentText = @"10s";
        _progressView.progress = 0.7;
       [self addSubview:_progressView];
        [_progressView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(64, 64));
        }];
        
        _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cancelButton setImage:[UIImage imageNamed:@"video_cancel"] forState:UIControlStateNormal];
        [self addSubview:_cancelButton];
        [_cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_progressView);
            make.right.equalTo(_progressView.mas_left).offset(-32);
            make.size.mas_equalTo(CGSizeMake(64, 64));
        }];
        
        _sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sureButton setImage:[UIImage imageNamed:@"video_sure_icon"] forState:UIControlStateNormal];
        [self addSubview:_sureButton];
        [_sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_progressView);
            make.left.equalTo(_progressView.mas_right).offset(32);
            make.size.mas_equalTo(CGSizeMake(64, 64));
        }];
    }
    return self;
}

@end
